#include <math.h>
#include "report.h"
#include "poisson.h"

int main(int argc, char ** argv)
{
  Poisson_t poi;
  Report_Real_t stats;
  double avg, sd;
  int i;
  double sum;

  Poisson_Init_Params(&poi, 1, 10.0);     /* the decimal point is CRITICAL */
  
  Report_Real_Init(&stats);

  for (i=0; i<100000; i++)
  {
    int val; 
    val = Poisson_Sample(&poi, 0);
    Report_Real_Update(&stats, (double) val);
  }
  
  Report_Real_Compute(&stats, &avg, &sd);
  
  if (fabs(avg - 10) > .1)
    return 1;
  
  if (fabs(sd*sd - 10) > .1)
    return 2;
  
  sum = 0;
  for (i=0; i<1000; i++)
    sum += exp(Poisson_LogProb(&poi, i, 0));
  
  if (fabs(sum - 1) > 1e-4)
    return 3;

  sum = 0;
  for (i=0; i<1000; i++)
    sum += Poisson_Prob(&poi, i, 0);
  
  if (fabs(sum - 1) > 1e-4)
    return 4;

  return 0;
}
